<template>
  <div id="taskPriority" v-loading="loading">
    <v-tableTitle
      :btnConfig="btnConfig"
      :tableSelectData="tableSelectData"
      :title="$t('ex.taskpriority')"
      @updatePriority="updatePriority"
    ></v-tableTitle>
    <v-table
      :hasEdit="false"
      :pageSize="pageSize"
      :page="page"
      :tableConfig="tableConfig"
      :tableData="tableData"
      :total="total"
      @findData="getTableData"
      @getTableData="getTableData"
      @searhData="searhData"
      @selectData="selectData"
      @upData="getTableData"
      ref="table"
    ></v-table>
    <el-dialog
      :modal="false"
      :visible.sync="dialogVisible"
      v-dialogDrag
      width="30%"
    >
      <v-input
        :detailData="inputData"
        :inputConfig="inputConfig"
        :rules="rules"
        ref="input"
      ></v-input>
      <span slot="footer" class="dialog-footer">
        <el-button :disabled="!this.btnPermNameList.includes('WM06010302')" @click="close">{{ $t("common.cancel") }}</el-button>
        <el-button :disabled="!this.btnPermNameList.includes('WM06010303')" type="primary" @click="inquire">{{
          $t("common.confirm")
        }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";
import input from "commons/Detail"

export default {
    name: "taskPriority",
    mixins: [baseMixin, config],
    data() {
        return {
            loading: false,
            updatePriorityStatus: false,
            tableConfig: [
                {
                    label: this.$t('outbound.permissiontype'),
                    prop: "tasktype",
                    input: "select",
                    options: this.getOptions("querycodeLkup/TASKTYPE")
                },
                {
                    label: this.$t('common.status'),
                    prop: "status",
                    input: "select",
                    options: this.getOptions("querycodeLkup/TMSTATUS")
                },
                {
                    label: this.$t('in.priority'),
                    prop: "priority",
                    input: "select",
                    options: this.getOptions("querycodeLkup/TMPRIORITY")
                },
                {
                    label: this.$t('config.sku'),
                    prop: "sku",
                    input: "input"
                },
                {
                    label: this.$t('ex.sourcekey'),
                    prop: "sourcekey",
                    input: "input"
                },
                {
                    label: this.$t('config.num'),
                    prop: "qty",
                    input: "input"
                },
                {
                    label: this.$t('outbound.fromloc'),
                    prop: "fromloc",
                    input: "input",
                },
                {
                    label: this.$t('config.toLoc'),
                    prop: "toloc",
                    input: "input"
                },
                {
                    label: this.$t('in.fromid'),
                    prop: "fromid",
                    input: "input"
                },
                {
                    label: this.$t('in.toid'),
                    prop: "toid",
                    input: "input"
                },
                {
                    label: this.$t('ex.rtxiswcstask'),
                    prop: "rtxiswcstask",
                    input: "input"
                },
                {
                    label: this.$t('outbound.user'),
                    prop: "userkey",
                    input: "input"
                },
                {
                    label: this.$t('out.wavekey'),
                    prop: "wavekey",
                    input: "input"
                },
                {
                    label: this.$t('out.taskgroup'),
                    prop: "rtxtaskgrp",
                    input: "input"
                },
            ],
            tableData: [],
          page: 1,
            pageSize: 10,
            total: 0,
            tableSelectData: [],
            tableSearhData: {},

            dialogVisible: false,
            inputData: {
                tasktype: "",
                wavekey: "",
                rtxtaskgrp: "",
                priority: ""
            },
            inputConfig: [
                [
                    {
                        type: "select",
                        label: this.$t('outbound.permissiontype'),
                        props: "tasktype",
                        options: this.getOptions("querycodeLkup/TASKTYPE")
                    },
                    {
                        type: "input",
                        label: this.$t('out.wavekey'),
                        props: "wavekey",
                    },
                    {
                        type: "input",
                        label: this.$t('out.taskgroup'),
                        props: "rtxtaskgrp",
                    },
                    {
                        type: "select",
                        label: this.$t('in.priority'),
                        props: "priority",
                        options: this.getOptions("querycodeLkup/TMPRIORITY")
                    },
                ]
            ],
            rules: {}
        };
    },
    computed: {
        btnConfig() {
            return [
                {label: this.$t('ex.updatePriority'), certigier: this.updatePriorityStatus||!this.btnPermNameList.includes('WM06010301'), invalid: "updatePriority"},
            ]
        }
    },
    created() {
    },
    methods: {
        updatePriority() {

          if (this.tableSelectData.length == 1) {
            this.inputData = {
              tasktype: this.tableSelectData[0].tasktype,
              wavekey: this.tableSelectData[0].wavekey,
              rtxtaskgrp: this.tableSelectData[0].rtxtaskgrp,
              priority: ""
            }
          }else if(this.tableSelectData.length > 1){
            this.$message.error(this.$t("msg.msg32"));
            return;
          }
          this.dialogVisible = true
        },
        close() {
            this.inputData = {
                tasktype: "",
                wavekey: "",
                rtxtaskgrp: "",
                priority: ""
            }
            this.dialogVisible = false;
        },
        inquire() {
            let selecteddescr = "";
            let array = this.getOptions("querycodeLkup/TASKTYPE");
            array.forEach(item => {
                if (item.code === this.inputData.tasktype) {
                    selecteddescr = item.description;
                }
            });
            if ('' == this.inputData.tasktype) {
              this.$message.error(this.$selectPlease('outbound.permissiontype'))
                return;
            }
            if ('' == this.inputData.priority) {
              this.$message.error(this.$selectPlease('in.priority'))
                return;
            }
            if ('' == this.inputData.wavekey && ''== this.inputData.rtxtaskgrp) {
                this.$message.error(this.$t('msg.msg31'));
                return;
            }
            this.$api.post(`/getTaskPriorityCount`, this.inputData).then(res => {
                
                    this.$confirm(`共计${res.bean}条${selecteddescr}优先级被修改，确认修改？`, '提示', {
                        confirmButtonText: this.$t('common.confirm'),
                        cancelButtonText: this.$t('common.cancel'),
                        type: 'warning'
                    }).then(() => {
                        this.$api.post(`/updateTaskPriority`, this.inputData).then(res => {
                            
                                this.close();
                                this.getTableData(1, {});
                            
                        })
                    }).catch(() => {
                    });
                
            }).catch(e => {
                this.$message.error(e);
            })
        },
        //选中的内容
        selectData(data) {
            this.tableSelectData = data;
        },
        async getTableData(page, data) {
            try {
                this.loading = true;
                let res = await this.$api.post(`/queryTaskPriority/${page}`, data);
                
                    this.tableData = res.page.list;
                  this.page = res.page.curpage;
                    this.pageSize = res.page.pageSize;
                    this.total = res.page.total;
                    this.updatePriorityStatus = this.tableData <= 0
                
            } catch (e) {
                this.$message.error(e);
            } finally {
                this.loading = false;
            }
        },
        //搜索的值
        searhData(data, up) {
            if (!up) {
                this.tableSearhData = data;
            } else {
                this.tableSearhData = data;
                this.getTableData(1, this.tableSearhData);
            }
        },
    },
    mounted() {
        
        this.$store.commit("setSkip", {});
        this.$store.commit("setNewFlag", false);
        this.$store.commit("setRouteData", {});
        this.getTableData(1, {});
    },
    watch: {},
    components: {
        "v-tableTitle": tableTitle,
        "v-table": table,
        "v-input": input
    }
};
</script>

<style scoped>
#taskPriority {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
